'''
Created on Jun 6, 2012

@author: thomas_dao
'''

from google.appengine.ext import ndb
from entity.entity import Interest, UserInterest, EventInterest


@ndb.tasklet
def get_all(**q_options):
    qry = Interest.query()
    data = yield qry.fetch_async(20, **q_options)
    raise ndb.Return(data)        

@ndb.tasklet
def get_by_author(author_key, **q_options):
    qry = UserInterest.query(UserInterest.author == author_key).order(-UserInterest.created_time)
    data = yield qry.fetch_async(20, **q_options)
    raise ndb.Return(data)  
            
@ndb.tasklet
def get_users(interest_key, **q_options):
    qry = UserInterest.query(UserInterest.interest == interest_key).order(-UserInterest.created_time)
    data = yield qry.fetch_async(20, **q_options)
    raise ndb.Return(data)              

@ndb.tasklet
def get_by_event(event_key, **q_options):
    qry = EventInterest.query(EventInterest.event == event_key).order(-EventInterest.created_time)
    data = yield qry.fetch_async(20, **q_options)
    raise ndb.Return(data) 

@ndb.tasklet
def get_events(interest_key, **q_options):
    qry = EventInterest.query(EventInterest.interest == interest_key).order(-EventInterest.created_time)
    data = yield qry.fetch_async(20, **q_options)
    raise ndb.Return(data) 
    
